package proto

import (
	"regexp"
	D "websocket_apn/define"
	"websocket_apn/log"
)

/*
复活
[DEBUG] [2024/05/04 20:51:50] [PRJ/websocket_apn/main_test.go]:[  192]:   MessageID: ↑↑↑↑↑ Client.15408
[DEBUG] [2024/05/04 20:51:50] [PRJ/websocket_apn/main_test.go]:[  196]:   S_HOLY_LAND_GAME_BACK_HOME - id:3109673861602
[DEBUG] [2024/05/04 20:51:50] [PRJ/websocket_apn/main_test.go]:[  197]:   PayloadBytes: 71 AB 00 00 00 14 00 03 32 7C 00 00 02D4 07 01 81 E2 08 00
游戏心跳机制
2024/05/04 20:32:07.781167 main_test.go:196: [0;32m[DEBUG][0mS_HOLY_LAND_GAME_HEART_BEAT - id:3109673861602
2024/05/04 20:32:07.781167 main_test.go:197: [0;32m[DEBUG][0m[PayloadBytes:  71 AB 00 00 00 12 00 03 32 70 00 00 02 D4 07 01 81 E2]

移动到某个塔
[DEBUG] [2024/05/04 20:07:37] [PRJ/websocket_apn/main_test.go]:[  196]:   S_HOLY_LAND_GAME_MOVE - id:3109673861602
[DEBUG] [2024/05/04 20:07:37] [PRJ/websocket_apn/main_test.go]:[  197]:   PayloadBytes: 71 AB 00 00 00 15 00 03 32 75 00 00 02D4 07 01 81 E2 08 B9 17
2
2024/05/04 20:23:05.286229 main_test.go:196: [0;32m[DEBUG][0mS_HOLY_LAND_GAME_AUTO_ATTACK - id:3109673861602
2024/05/04 20:23:05.286229 main_test.go:197: [0;32m[DEBUG][0m[PayloadBytes:  71 AB 00 00 00 15 00 03 32 81 00 00 02 D4 07 01 81 E2 08 DF 0F]
DC 0F //1 初
D1 0F //2 初
DB 0F //3 初 朔风台
B9 17 //4 初
BE 17 //5 中
 //6 中
DA 0F //7 初
DD 0F //8 初
D3 0F //9 初
 //10 中
A1 1F //11 高
BA 17 //12 中 众合祭坛
D9 0F //13 初 夜叉台
DF 0F //14 初
DE 0F //15 初 隐雾台
 //16 初
 //17 初
 //18 中
BB 17 //19 中
D5 0F //20 初
D7 0F //21 初
D6 0F //22 初

移动到大本营
 //
 //
 //
 //
 //
 //
EC 07 //7
 //
 //
 //
 //
 //
九幽宝珠助力礼包
[DEBUG] [2024/09/28 11:42:36] [PRJ/websocket_apn/main_test.go]:[  193]:   ↑↑↑↑↑ S_MALL_BUY_GOODS - len:28
[DEBUG] [2024/09/28 11:42:36] [PRJ/websocket_apn/main_test.go]:[  200]:   PayloadBytes: 71 AB 00 00 00 1C 00 00 50 79 00 00 02D4 07 01 81 E2 08 E6 DF AA 99 02 10 01 18 00
*/

//九幽争霸-查看灵气状态
func ParaHolyLandSpiInfo(dataBytes []byte) D.HolyLandSpiInfo {
	var info D.HolyLandSpiInfo
	data := BytesToHexStr(dataBytes)
	// 定义正则表达式
	re := regexp.MustCompile(`12[0-9A-F]{2}((?:3[0-9]){1,9})1A[0-9A-F]{2}((?:3[0-9]){1,9})22[0-9A-F]{2}((?:3[0-9]){1,9})2A[0-9A-F]{2}((?:3[0-9]){1,9})30((?:[0-9A-F]{2})+?)38([0-9A-F]{12})40([0-9A-F]{2})48([0-9A-F]{12})`)
	res := re.FindAllStringSubmatch(data, -1)
	if len(res) == 0 {
		log.Errorf("解析数据失败-%s", data)
	}
	// 打印结果
	if len(res) > 0 && len(res[0]) > 0 {
		//log.Infof("%+v", regRes[1:])
		regRes := res[0]
		info = D.HolyLandSpiInfo{
			Spi:         HexDataStrToInt64(regRes[1]),   //当前灵气
			SpiLimit:    HexDataStrToInt64(regRes[2]),   //灵气上线
			Save:        HexDataStrToInt64(regRes[3]),   //当前存储灵气
			SaveLimit:   HexDataStrToInt64(regRes[4]),   //存储灵气上线
			CombatValue: ParaIntDataByHexStr(regRes[5]), //妖力
			EndTime:     ParaHexStrToTimeMs(regRes[6]),  //活动时间
			Defeated:    ParaIntDataByHexStr(regRes[7]), //被击败
			EndATime:    ParaHexStrToTimeMs(regRes[8]),  //结束时间
		}
		log.Infof("九幽争霸-当前灵力%d, 灵力上限%d, 存储灵力%d, 存储上限%d", info.Spi, info.SpiLimit, info.Save, info.SpiLimit)
	}
	return info
}

/*
71 AB 00 00 06 5E 00 00 25 36 00 00 02 D4 07 01 81 E2 08 00 12 32 08 A1 1F 12 2B 08 E1 EC 89 EC 73 10 D8 94 1C 18 01 22 0C E4 BF AE E4 BB 99 E7 8B 82 E5 BE 92 28 00 30 10 38 A9 E6 BD 01 40 26 48 04 50 00 58 00 18 00 12 32 08 B9 17 12 2B 08 E1 EC 89 EC 73 10 D8 94 1C 18 01 22 0C E4 BF AE E4 BB 99 E7 8B 82 E5 BE 92 28 00 30 10 38 A9 E6 BD 01 40 26 48 04 50 00 58 00 18 00 12 31 08 BA 17 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 31 08 BB 17 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 05 08 BC 17 18 00 12 35 08 BD 17 12 2E 08 EC B2 87 EC 73 10 94 E2 1D 18 01 22 0F E5 A5 94 E6 94 BE E7 9A 84 E5 AE 97 E9 97 A8 28 00 30 11 38 A5 E6 BD 01 40 2C 48 02 50 00 58 00 18 00 12 35 08 BE 17 12 2E 08 EC B2 87 EC 73 10 94 E2 1D 18 01 22 0F E5 A5 94 E6 94 BE E7 9A 84 E5 AE 97 E9 97 A8 28 00 30 11 38 A5 E6 BD 01 40 2C 48 02 50 00 58 00 18 00 12 32 08 D1 0F 12 2B 08 E1 EC 89 EC 73 10 D8 94 1C 18 01 22 0C E4 BF AE E4 BB 99 E7 8B 82 E5 BE 92 28 00 30 10 38 A9 E6 BD 01 40 26 48 04 50 00 58 00 18 00 12 32 08 D2 0F 12 2B 08 E1 EC 89 EC 73 10 D8 94 1C 18 01 22 0C E4 BF AE E4 BB 99 E7 8B 82 E5 BE 92 28 00 30 10 38 A9 E6 BD 01 40 26 48 04 50 00 58 00 18 00 12 31 08 D3 0F 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 31 08 D4 0F 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 31 08 D5 0F 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 31 08 D6 0F 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 31 08 D7 0F 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 34 08 D8 0F 12 2D 08 A1 DD 86 EC 73 10 C0 89 1A 18 E4 B6 0D 22 0C E8 87 B3 E5 B0 8A E9 81 93 E5 9C BA 28 01 30 11 38 A4 E6 BD 01 40 1F 48 02 50 00 58 00 18 01 12 2C 08 D9 0F 12 25 08 D9 F8 8A EC 73 10 80 82 10 18 02 22 06 E4 B9 9D E9 97 A8 28 01 30 0F 38 AA E6 BD 01 40 27 48 02 50 00 58 00 18 00 12 35 08 DA 0F 12 2E 08 EC B2 87 EC 73 10 94 E2 1D 18 01 22 0F E5 A5 94 E6 94 BE E7 9A 84 E5 AE 97 E9 97 A8 28 00 30 11 38 A5 E6 BD 01 40 2C 48 02 50 00 58 00 18 00 12 35 08 DB 0F 12 2E 08 EC B2 87 EC 73 10 94 E2 1D 18 01 22 0F E5 A5 94 E6 94 BE E7 9A 84 E5 AE 97 E9 97 A8 28 00 30 11 38 A5 E6 BD 01 40 2C 48 02 50 00 58 00 18 00 12 32 08 DC 0F 12 2B 08 E1 EC 89 EC 73 10 D8 94 1C 18 01 22 0C E4 BF AE E4 BB 99 E7 8B 82 E5 BE 92 28 00 30 10 38 A9 E6 BD 01 40 26 48 04 50 00 58 00 18 00 12 32 08 DD 0F 12 2B 08 E1 EC 89 EC 73 10 D8 94 1C 18 01 22 0C E4 BF AE E4 BB 99 E7 8B 82 E5 BE 92 28 00 30 10 38 A9 E6 BD 01 40 26 48 04 50 00 58 00 18 00 12 31 08 DE 0F 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 05 08 DF 0F 18 01 12 32 08 E9 07 12 2B 08 E1 EC 89 EC 73 10 D8 94 1C 18 01 22 0C E4 BF AE E4 BB 99 E7 8B 82 E5 BE 92 28 00 30 10 38 A9 E6 BD 01 40 26 48 04 50 00 58 00 18 00 12 32 08 EA 07 12 2B 08 FF B4 88 EC 73 10 F0 A7 13 18 01 22 0C E9 98 B2 E7 88 86 E5 A4 A7 E9 98 9F 28 01 30 0B 38 A6 E6 BD 01 40 29 48 02 50 00 58 00 18 00 12 2C 08 EB 07 12 25 08 9D 9E 8A EC 73 10 DC C3 17 18 03 22 06 E8 8A B1 E5 9F 8E 28 01 30 03 38 A9 E6 BD 01 40 29 48 02 50 00 58 00 18 00 12 31 08 EC 07 12 2A 08 8D AE 88 EC 73 10 E4 84 20 18 E3 B6 0D 22 09 E7 8E 84 E5 A4 A9 E9 98 81 28 00 30 0E 38 A6 E6 BD 01 40 25 48 03 50 00 58 00 18 00 12 29 08 ED 07 12 22 08 EB BD 81 EC 73 10 F8 CA 0C 18 03 22 03 E7 A5 9E 28 01 30 03 38 9B E6 BD 01 40 24 48 02 50 00 58 00 18 01 12 2C 08 EE 07 12 25 08 E6 EB 89 EC 73 10 88 C2 10 18 04 22 06 47 47 62 6F 6F 6D 28 01 30 0D 38 A9 E6 BD 01 40 28 48 03 50 00 58 00 18 00 12 32 08 EF 07 12 2B 08 C7 FD 81 EC 73 10 98 90 11 18 01 22 0C E4 B8 80 E6 9E 95 E6 A7 90 E8 8A B1 28 01 30 0C 38 9C E6 BD 01 40 21 48 01 50 00 58 00 18 00 12 34 08 F0 07 12 2D 08 A1 DD 86 EC 73 10 C0 89 1A 18 E4 B6 0D 22 0C E8 87 B3 E5 B0 8A E9 81 93 E5 9C BA 28 01 30 11 38 A4 E6 BD 01 40 1F 48 02 50 00 58 00 18 00 12 2C 08 F1 07 12 25 08 D9 F8 8A EC 73 10 80 82 10 18 02 22 06 E4 B9 9D E9 97 A8 28 01 30 0F 38 AA E6 BD 01 40 27 48 02 50 00 58 00 18 00 12 32 08 F2 07 12 2B 08 95 C9 86 EC 73 10 C8 CB 11 18 01 22 0C E6 B5 AE E8 8B A5 E5 AE 89 E7 94 9F 28 01 30 07 38 A3 E6 BD 01 40 29 48 02 50 00 58 00 18 00 12 35 08 F3 07 12 2E 08 EC B2 87 EC 73 10 94 E2 1D 18 01 22 0F E5 A5 94 E6 94 BE E7 9A 84 E5 AE 97 E9 97 A8 28 00 30 11 38 A5 E6 BD 01 40 2C 48 02 50 00 58 00 18 00 12 05 08 F4 07 18 00

*/
//九幽争霸-查看地图信息
func ParaHolyLandMapInfo(dataBytes []byte) D.HolyLandMapInfo {
	var allInfo D.HolyLandMapInfo
	data := BytesToHexStr(dataBytes)
	// 定义正则表达式                           1 地址ID     2 是否战败
	re1 := regexp.MustCompile(`120508([0-9A-F]{4})18(0[0-9])`)
	//												1 地址ID                     2 妖盟ID         3						4     								5 妖盟名称  				6			7				8				9				10			11				12				13
	re2 := regexp.MustCompile(`12[0-9A-F]{2}08([0-9A-F]{4})12[0-9A-F]{2}08([0-9A-F]{10})10((?:[0-9A-F]{2}){1,5})18((?:[0-9A-F]{2}){1,4})22[0-9A-F]{2}((?:[0-9A-F]{2})+?)28([0-9A-F]{2})30([0-9A-F]{2})38([0-9A-F]{8})40([0-9A-F]{2})48([0-9A-F]{2})50([0-9A-F]{2})58([0-9A-F]{2})18([0-9A-F]{2})`)
	res := re1.FindAllStringSubmatch(data, -1)
	res1 := re2.FindAllStringSubmatch(data, -1)
	for _, regRes := range res {
		if len(regRes) > 0 {
			info := D.HolyLandAddInfo{
				PlaceId: int(ParaIntDataByHexStr(regRes[1])), //1 地址ID
				Place:   regRes[1],                           //1 地址ID
				Res13:   int(ParaIntDataByHexStr(regRes[2])), //13
			}
			if info.PlaceId < 1500 {
				info.IsYM = true
			}
			log.Infof("%+v", info)
			allInfo.Add = append(allInfo.Add, info)
		}
	}
	for _, regRes := range res1 {
		if len(regRes) > 0 {
			info := D.HolyLandAddInfo{
				PlaceId: int(ParaIntDataByHexStr(regRes[1])),  //1 地址ID
				Place:   regRes[1],                            //1 地址ID
				YmID:    regRes[2],                            //2 妖盟ID
				Res3:    int(ParaIntDataByHexStr(regRes[3])),  //3
				Res4:    int(ParaIntDataByHexStr(regRes[4])),  //4
				YMName:  HexDataStrToStr(regRes[5]),           //5 妖盟名称
				Res6:    int(ParaIntDataByHexStr(regRes[6])),  //6
				Res7:    int(ParaIntDataByHexStr(regRes[7])),  //7
				Res8:    int(ParaIntDataByHexStr(regRes[8])),  //8
				Res9:    int(ParaIntDataByHexStr(regRes[9])),  //9
				Res10:   int(ParaIntDataByHexStr(regRes[10])), //10
				Res11:   int(ParaIntDataByHexStr(regRes[11])), //11
				Res12:   int(ParaIntDataByHexStr(regRes[12])), //12
				Res13:   int(ParaIntDataByHexStr(regRes[13])), //13
			}
			if info.PlaceId < 1500 {
				info.IsYM = true
			}
			log.Infof("%+v", info)
			allInfo.Add = append(allInfo.Add, info)
		}
	}
	return allInfo
}
